package com.threegold.listviewsample.slice;

import com.threegold.listview.ListView;
import com.threegold.listviewsample.ResourceTable;
import com.threegold.listviewsample.provider.CommonListItemProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;

public class EmptyAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_empty);

        ListView listView = (ListView) findComponentById(ResourceTable.Id_listView);

        Component emptyView = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_empty_view, listView, false);
        listView.setEmptyView(emptyView);

        // 创建适配器
        CommonListItemProvider itemProvider = new CommonListItemProvider(this);

        listView.setItemProvider(itemProvider);
        // 延时模拟数据加载，然后显示emptyView，该方法通常在没有数据时展示需要显示的emptyView提示用户
        // 注意，如果需要一开始就显示emptyView，则需要在setItemProvider方法之前使用displayEmptyView设置为true。
        getUITaskDispatcher().delayDispatch(new Runnable() {
            @Override
            public void run() {
                listView.displayEmptyView(true);
                itemProvider.notifyDataChanged();
            }
        }, 1000);
    }

}
